﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Edge.Common.ComponentModel.Parameters;
using Edge.OAuth;
using Shop.Web.AppCode;

namespace Shop.Web
{
    public partial class VK : ShopBasePage
    {
        [QueryParameter("code", IsRequired = false)]
        public string code;

       
        protected void Page_Load(object sender, EventArgs e)
        {
            WebParameterAttribute.SetValues(this, Request);
            bool isFB = false;
            if (!string.IsNullOrEmpty(code))
            {
                var clientO = new OAuth2(ConfigurationManager.AppSettings["VKApi"],
                                     ConfigurationManager.AppSettings["VKApiKey"], AuthUrl, TokenUrl, ReturnUrl)
                              {Code = code};
                //clientO = isFB ? new OAuth2("296841663712917", "4ff397794668cbedef8ec54da9568e3d", "https://www.facebook.com/dialog/oauth", "https://graph.facebook.com/oauth/access_token", "http://morlin.ru/admin/test.aspx?isFB=true") : new OAuth2(ConfigurationManager.AppSettings["VKApi"], ConfigurationManager.AppSettings["VKApiKey"], "http://api.vkontakte.ru/oauth/authorize", "https://api.vkontakte.ru/oauth/access_token", "http://morlin.ru/admin/test.aspx");
//                OAuth2Token token;
//                if (isFB)
//                    token = clientO.GetAccessToken(new Dictionary<string, string> { { "client_secret", "4ff397794668cbedef8ec54da9568e3d" } }, OAuth2.AccessTokenType.Dictionary); //получаем маркер доступа
//                else
                var token = clientO.GetAccessToken(new Dictionary<string, string> { { "client_secret", ConfigurationManager.AppSettings["VKApiKey"] } }, OAuth2.AccessTokenType.JsonDictionary);
                if (token != null)
                {
                    if (token.dictionary_token != null)
                    {
//                        ltVK.Text = isFB ?
//                            OAuth2UserData.GetFacebookUserData(token.dictionary_token["access_token"]) :
//                                OAuth2UserData.GetVKUserData(token.dictionary_token["access_token"],
//                                                                      new Dictionary<string, string> { { "uid", token.dictionary_token["user_id"] } });
                    }

                }
            } 
        }
    }
}
